﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db;
using HengTong.Model.Db.Other;
using TiaoTaoHelper.Wtm.Models;


namespace HengTong.ViewModel.Visitor.SysVisitorReasonVms
{
    public partial class SysVisitorReasonListVm : BasePagedListVM<SysVisitorReasonView, SysVisitorReasonSearcher>
    {

        protected override IEnumerable<IGridColumn<SysVisitorReasonView>> InitGridHeader()
        {
            return new List<GridColumn<SysVisitorReasonView>>{
                this.MakeGridHeader(x => x.ReasonName),
                this.MakeGridHeader(x => x.GroupName),
                this.MakeGridHeader(x => x.IsActive),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysVisitorReasonView> GetSearchQuery()
        {
            var query = DC.Set<SysVisitorReason>()
                .CheckContain(Searcher.ReasonName, x=>x.ReasonName)
                .CheckEqual(Searcher.GroupId, x=>x.GroupId)
                .CheckEqual(Searcher.IsActive, x=>x.IsActive)
                .Select(x => new SysVisitorReasonView
                {
				    ID = x.ID,
                    ReasonName = x.ReasonName,
                    GroupName = x.Group.GroupName,
                    IsActive = x.IsActive,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysVisitorReasonView : SysVisitorReason{
        [Display(Name = "_Admin.GroupName")]
        public String GroupName { get; set; }

    }
}
